﻿namespace Smart.Utils.UI.BarcodeLib
{
    using System;

    internal class Code11 : BarcodeCommon, IBarcode
    {
        private string[] C11_Code = new string[] { "101011", "1101011", "1001011", "1100101", "1011011", "1101101", "1001101", "1010011", "1101001", "110101", "101101", "1011001" };

        public Code11(string input)
        {
            base.Raw_Data = input;
        }

        private string Encode_Code11()
        {
            int num3;
            char ch2;
            if (!BarcodeEdit.CheckNumericOnly(base.Raw_Data.Replace("-", "")))
            {
                throw new Exception("EC11-1: Numeric data and '-' Only");
            }
            int num = 1;
            int num2 = 0;
            string str = base.Raw_Data;
            for (num3 = base.Raw_Data.Length - 1; num3 >= 0; num3--)
            {
                if (num == 10)
                {
                    num = 1;
                }
                if (base.Raw_Data[num3] != '-')
                {
                    ch2 = base.Raw_Data[num3];
                    num2 += int.Parse(ch2.ToString()) * num++;
                }
                else
                {
                    num2 += 10 * num++;
                }
            }
            str = str + ((num2 % 11)).ToString();
            if (base.Raw_Data.Length >= 1)
            {
                num = 1;
                int num5 = 0;
                for (num3 = str.Length - 1; num3 >= 0; num3--)
                {
                    if (num == 9)
                    {
                        num = 1;
                    }
                    if (str[num3] != '-')
                    {
                        ch2 = str[num3];
                        num5 += int.Parse(ch2.ToString()) * num++;
                    }
                    else
                    {
                        num5 += 10 * num++;
                    }
                }
                str = str + ((num5 % 11)).ToString();
            }
            string str2 = "0";
            string str3 = this.C11_Code[11] + str2;
            foreach (char ch in str)
            {
                int index = (ch == '-') ? 10 : int.Parse(ch.ToString());
                str3 = str3 + this.C11_Code[index] + str2;
            }
            return (str3 + this.C11_Code[11]);
        }

        public string Encoded_Value
        {
            get
            {
                return this.Encode_Code11();
            }
        }
    }
}

